Skip to content

Sheffield | 25-SDC-Nov | Sheida Shabankari | Sprint 2 |Implement linked list in python#101

Open
sheida-shab wants to merge 7 commits intoCodeYourFuture:mainfrom
sheida-shab:Feat-Implement-linked-list-in-Python
Open

Sheffield | 25-SDC-Nov | Sheida Shabankari | Sprint 2 |Implement linked list in python#101
sheida-shab wants to merge 7 commits intoCodeYourFuture:mainfrom
sheida-shab:Feat-Implement-linked-list-in-Python

Conversation

@sheida-shab
Copy link

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

This PR implements a doubly linked list in Python with O(1) time complexity for all required operations.

Added a Node class to represent elements with value, next, and previous references.

Implemented push_head to insert elements at the head and return a node handle for constant-time removal.

Implemented pop_tail to remove and return the value of the tail node.

Implemented remove to delete a node from the list using its handle, without traversing the list.

Properly maintains head and tail references and updates links for all edge cases (empty list, single node, head, tail, and middle nodes).

All provided tests pass successfully.

@sheida-shab sheida-shab added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Complexity The name of the module. labels Feb 15, 2026
Comment on lines 34 to 41
elif self.head==self.tail:
node_value=self.head.value
self.head=None
self.tail=None
else:
node_value=self.tail.value
previous_node=self.tail.previous
self.tail=previous_node
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also consider calling remove() to remove the tail -- less code to maintain.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it.

Comment on lines 67 to 68
node_to_remove.next=None
node_to_remove.previous=None
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not also clearing the reference of the removed tail in pop_tail()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Feb 27, 2026
@sheida-shab sheida-shab added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Feb 27, 2026
Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good.

Comment on lines 34 to 42
elif self.head==self.tail:
node_to_remove = self.head
node_value = node_to_remove.value
self.remove(node_to_remove)

else:
node_to_remove = self.tail
node_value = node_to_remove.value
self.remove(node_to_remove)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this work the same as the code on line 34-42?

  node_value = self.tail.value
  self.remove(self.tail)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the point now.
remove() handles both single-node and multiple-node cases,
so I simplified pop_tail() to just call remove(self.tail).
This makes the code shorter and cleaner.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Complete Volunteer to add when work is complete and all review comments have been addressed. labels Feb 27, 2026
@cjyuan
Copy link

cjyuan commented Feb 27, 2026

Just noticed you removed these two lines from removed():

        node_to_remove.next=None
        node_to_remove.previous=None     

Why?

@sheida-shab
Copy link
Author

You are right.
After the refactor, pop_tail() no longer removes nodes directly.
That responsibility was moved to remove(), so clearing the node references should also stay in remove().
I understand this now and will keep the code there.

@sheida-shab sheida-shab added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Feb 28, 2026
@cjyuan
Copy link

cjyuan commented Feb 28, 2026

I could not find the code for clearing references in remove().

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Feb 28, 2026
@sheida-shab
Copy link
Author

You’re right, that was an oversight on my part.
I’ve added the reference cleanup back into remove().

@sheida-shab sheida-shab added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Feb 28, 2026
@cjyuan
Copy link

cjyuan commented Feb 28, 2026

All good now. Well done.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Complexity The name of the module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants